<?php

/* @var $this yii\web\View */
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\helpers\Url;
use app\assets\ComposeAsset;
ComposeAsset::register($this);

$this->title = '系统配置';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="page-title">
  <div>
    <h1><i class="fa fa-cog"></i> 系统配置</h1>
    <ul class="breadcrumb side">
      <li><i class="fa fa-home fa-lg"></i></li>
      <li class="active"><a href="#">系统配置</a></li>
    </ul>
  </div>
</div>

<div class='card'>
<?php $form = ActiveForm::begin(); ?>

<?php
  if(isset($tip)&&$tip===true){
    if($model->hasErrors()){
?>
      <div class="alert alert-danger" role="alert">
        <?php
            foreach($model->getErrors("") as $key=>$value){
              echo $value."<br>";
            }
        ?>
      </div>
<?php
    }else{
?>
      <div class="alert alert-success" role="alert">系统设置成功！</div>
<?php
    }
  }
?>
<?=$form->field($model, 'site_name')?>
<?=$form->field($model, 'site_addr')?>
<?=$form->field($model, 'site_reg_id')?>
<?=$form->field($model, 'sms_user')?>
<?=$form->field($model, 'sms_password')->passwordInput()?>
<?=Html::activeHiddenInput($model,'useagreement')?>
<div class="compose-body">
  <div id="alerts" style='font-weight:bold;'>网站使用协议</div>
  <div style='border:2px solid #ccc; border-radius:5px;padding:5px;'>
    <div class="btn-toolbar editor" data-role="editor-toolbar" data-target="#editor" >
      <div class="btn-group">
        <a class="btn dropdown-toggle" data-toggle="dropdown" title="字体尺寸"><i class="fa fa-text-height"></i>&nbsp;<b class="caret"></b></a>
        <ul class="dropdown-menu">
          <li>
            <a data-edit="fontSize 5">
              <span style="font-size:17px">大</span>
            </a>
          </li>
          <li>
            <a data-edit="fontSize 3">
              <span style="font-size:14px">中</span>
            </a>
          </li>
          <li>
            <a data-edit="fontSize 1">
              <span style="font-size:11px">小</span>
            </a>
          </li>
        </ul>
      </div>

      <div class="btn-group">
        <a class="btn" data-edit="bold" title="加粗 (Ctrl/Cmd+B)"><i class="fa fa-bold"></i></a>
        <a class="btn" data-edit="italic" title="斜体 (Ctrl/Cmd+I)"><i class="fa fa-italic"></i></a>
        <a class="btn" data-edit="strikethrough" title="删除线"><i class="fa fa-strikethrough"></i></a>
        <a class="btn" data-edit="underline" title="下划线 (Ctrl/Cmd+U)"><i class="fa fa-underline"></i></a>
      </div>

      <div class="btn-group">
        <a class="btn" data-edit="insertunorderedlist" title="项目符号"><i class="fa fa-list-ul"></i></a>
        <a class="btn" data-edit="insertorderedlist" title="编号"><i class="fa fa-list-ol"></i></a>
        <a class="btn" data-edit="outdent" title="减少缩进 (Shift+Tab)"><i class="fa fa-dedent"></i></a>
        <a class="btn" data-edit="indent" title="缩进 (Tab)"><i class="fa fa-indent"></i></a>
      </div>

      <div class="btn-group">
        <a class="btn" data-edit="justifyleft" title="左对齐 (Ctrl/Cmd+L)"><i class="fa fa-align-left"></i></a>
        <a class="btn" data-edit="justifycenter" title="居中 (Ctrl/Cmd+E)"><i class="fa fa-align-center"></i></a>
        <a class="btn" data-edit="justifyright" title="右对齐 (Ctrl/Cmd+R)"><i class="fa fa-align-right"></i></a>
        <a class="btn" data-edit="justifyfull" title="两端对齐 (Ctrl/Cmd+J)"><i class="fa fa-align-justify"></i></a>
      </div>

      <div class="btn-group">
        <a class="btn dropdown-toggle" data-toggle="dropdown" title="超链接"><i class="fa fa-link"></i></a>
        <div class="dropdown-menu input-append">
          <input class="span2" placeholder="URL" type="text" data-edit="createLink" />
          <button class="btn" type="button">添加</button>
        </div>
        <a class="btn" data-edit="unlink" title="移除超链接"><i class="fa fa-cut"></i></a>
      </div>
      <div class="btn-group">
        <a class="btn" data-edit="undo" title="拆销 (Ctrl/Cmd+Z)"><i class="fa fa-undo"></i></a>
        <a class="btn" data-edit="redo" title="重做 (Ctrl/Cmd+Y)"><i class="fa fa-repeat"></i></a>
      </div>
    </div>

    <div id="editor" class="editor-wrapper" style='border:1px solid #ccc;'><?php echo $model->useagreement;?></div>
  </div>
</div>
<br>
<?=$form->field($model, 'logo_img_file')->fileInput()?>
<?php
  if(!isset($model->logo_img)||(is_null($model->logo_img))||$model->logo_img==''){
    echo Html::img(Url::base().'/uploads/logo_default.jpg',['width'=>200,'id'=>'sysconfigform-logo','style'=>'margin-bottom:20px;']);
  }else{
    echo Html::img(Url::base().'/'.$model->logo_img,['width'=>200,'id'=>'sysconfigform-logo','style'=>'margin-bottom:20px;']);
  }
?>

<div class='form-group'>
<?= Html::submitButton('提交', ['class' => 'btn btn-warning','id'=>'sysconfigform-submit']) ?>
</div>
<?php ActiveForm::end() ?>
</div>

<!-- /compose -->
<?php $this->beginBlock('compose-js') ?>
/* WYSIWYG EDITOR */

function init_wysiwyg() {

if( typeof ($.fn.wysiwyg) === 'undefined'){ return; }
console.log('init_wysiwyg');

   function init_ToolbarBootstrapBindings() {
     var fonts = ['Serif', 'Sans', 'Arial', 'Arial Black', 'Courier',
         'Courier New', 'Comic Sans MS', 'Helvetica', 'Impact', 'Lucida Grande', 'Lucida Sans', 'Tahoma', 'Times',
         'Times New Roman', 'Verdana'
       ],
       fontTarget = $('[title=Font]').siblings('.dropdown-menu');
     $.each(fonts, function(idx, fontName) {
       fontTarget.append($('<li><a data-edit="fontName ' + fontName + '" style="font-family:\'' + fontName + '\'">' + fontName + '</a></li>'));
     });
     $('a[title]').tooltip({
       container: 'body'
     });
     $('.dropdown-menu input').click(function() {
         return false;
       })
       .change(function() {
         $(this).parent('.dropdown-menu').siblings('.dropdown-toggle').dropdown('toggle');
       })
       .keydown('esc', function() {
         this.value = '';
         $(this).change();
       });

     $('[data-role=magic-overlay]').each(function() {
       var overlay = $(this),
         target = $(overlay.data('target'));
       overlay.css('opacity', 0).css('position', 'absolute').offset(target.offset()).width(target.outerWidth()).height(target.outerHeight());
     });

     if ("onwebkitspeechchange" in document.createElement("input")) {
       var editorOffset = $('#editor').offset();

       $('.voiceBtn').css('position', 'absolute').offset({
         top: editorOffset.top,
         left: editorOffset.left + $('#editor').innerWidth() - 35
       });
     } else {
       $('.voiceBtn').hide();
     }
   }

   function showErrorAlert(reason, detail) {
     var msg = '';
     if (reason === 'unsupported-file-type') {
       msg = "Unsupported format " + detail;
     } else {
       console.log("error uploading file", reason, detail);
     }
     $('<div class="alert"> <button type="button" class="close" data-dismiss="alert">&times;</button>' +
       '<strong>File upload error</strong> ' + msg + ' </div>').prependTo('#alerts');
   }

  $('.editor-wrapper').each(function(){
 var id = $(this).attr('id');	//editor-one

 $(this).wysiwyg({
   toolbarSelector: '[data-target="#' + id + '"]',
   fileUploadError: showErrorAlert
 });
});


   window.prettyPrint;
   prettyPrint();

};


/* COMPOSE */

function init_compose() {
  if( typeof ($.fn.slideToggle) === 'undefined'){ return; }
  console.log('init_compose');

  $('#compose, .compose-close').click(function(){
    $('.compose').slideToggle();
  });

};
$(document).ready(function() {
  init_wysiwyg();
  init_compose();

  //LOGO上传
  $('#sysconfigform-logo_img_file').change(function(){
    var fr=new FileReader();
    fr.onload=function(){
      var preview=this.result;
      $('#sysconfigform-logo').prop('src',preview);
    }
    fr.readAsDataURL(this.files[0]);
  });

  $('#sysconfigform-submit').click(function(){
    $('#sysconfigform-useagreement').val($('#editor').html());
  });

});



<?php $this->endBlock() ?>
<?php $this->registerJs($this->blocks['compose-js'],\yii\web\View::POS_END); ?>
